import request from '../utils/request';

// 报销申请相关API
export const expenseApi = {
  // 获取报销申请列表
  getExpenseList: (params) => {
    return request.get('/api/expenses', { params });
  },

  // 获取报销申请详情
  getExpenseDetail: (id) => {
    return request.get(`/api/expenses/${id}`);
  },

  // 创建报销申请
  createExpense: (data) => {
    return request.post('/api/expenses', data);
  },

  // 更新报销申请
  updateExpense: (id, data) => {
    return request.put(`/api/expenses/${id}`, data);
  },

  // 删除报销申请
  deleteExpense: (id) => {
    return request.delete(`/api/expenses/${id}`);
  },

  // 提交报销申请
  submitExpense: (id) => {
    return request.post(`/api/expenses/${id}/submit`);
  },

  // 审批报销申请
  approveExpense: (id, data) => {
    return request.post(`/api/expenses/${id}/approve`, data);
  },

  // 拒绝报销申请
  rejectExpense: (id, data) => {
    return request.post(`/api/expenses/${id}/reject`, data);
  },

  // 获取报销类型
  getExpenseTypes: () => {
    return request.get('/api/expenses/types');
  },

  // 获取报销统计
  getExpenseStatistics: (params) => {
    return request.get('/api/expenses/statistics', { params });
  },

  // 上传报销凭证
  uploadExpenseVoucher: (expenseId, file) => {
    const formData = new FormData();
    formData.append('file', file);
    return request.post(`/api/expenses/${expenseId}/vouchers`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  // 下载报销凭证
  downloadExpenseVoucher: (expenseId, voucherId) => {
    return request.get(`/api/expenses/${expenseId}/vouchers/${voucherId}/download`, {
      responseType: 'blob'
    });
  },

  // 获取我的报销申请
  getMyExpenses: (params) => {
    return request.get('/api/expenses/my', { params });
  },

  // 获取待审批报销
  getPendingExpenses: (params) => {
    return request.get('/api/expenses/pending', { params });
  }
};
